package com.fanqiechaodan.templatemethod;

/**
 * @author fanqiechaodan
 * @Classname CoffeeMaker
 * @Description 咖啡抽象类
 */
public abstract class CoffeeMaker {

    public final void makeCoffee() {
        boilWater();
        brewCoffee();
        pourInCup();
        if (isCondiments()) {
            addCondiments();
        }
    }

    private void boilWater() {
        System.out.println("煮水");
    }

    protected abstract void brewCoffee();

    private void pourInCup() {
        System.out.println("倒入杯子中");
    }

    /**
     * 钩子函数;是否加入调料,由子类决定是否重写
     *
     * @return
     */
    protected boolean isCondiments() {
        return true;
    }

    protected abstract void addCondiments();
}
